USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Addresses-Insert]    Script Date: [[20120914064947]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064947]]
-- Description:	Insert record into table [dbo].[Addresses]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Addresses-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Addresses-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Addresses-Insert]
	/*@Address_RowNumber int =Null OUTPUT , 
	@Address_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Address_Code varchar(50) =Null  , 
	@Country_ID uniqueidentifier =Null  , 
	@State_NameAr varchar(50) =Null  , 
	@State_NameEn varchar(50) =Null  , 
	@Town_NameAr varchar(50) =Null  , 
	@Town_NameEn varchar(50) =Null  , 
	@Address_NameAr varchar(50) =Null  , 
	@Address_NameEn varchar(50) =Null  , 
	@Postal_Code varchar(50) =Null  , 
	@Address_Notes varchar(max) =Null  , 
	@Address_Search varchar(max) =Null  , 
	@Address_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Addresses](/*[Address_ID], [Dealer_ID], [Address_Code], [Country_ID], [State_NameAr], [State_NameEn], [Town_NameAr], [Town_NameEn], [Address_NameAr], [Address_NameEn], [Postal_Code], [Address_Notes], [Address_Search]*/)
	VALUES     (/*@Address_ID, @Dealer_ID, @Address_Code, @Country_ID, @State_NameAr, @State_NameEn, @Town_NameAr, @Town_NameEn, @Address_NameAr, @Address_NameEn, @Postal_Code, @Address_Notes, @Address_Search*/)

	/*SELECT @Address_RowNumber = [Address_RowNumber], @Address_TimeStamp = [Address_TimeStamp]
    FROM [dbo].[Addresses]
    WHERE  ( [Address_ID] =@Address_ID )
	AND  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [Address_Code] =@Address_Code )
	AND  ( [Country_ID] =@Country_ID )
	AND  ( [State_NameAr] =@State_NameAr )
	AND  ( [State_NameEn] =@State_NameEn )
	AND  ( [Town_NameAr] =@Town_NameAr )
	AND  ( [Town_NameEn] =@Town_NameEn )
	AND  ( [Address_NameAr] =@Address_NameAr )
	AND  ( [Address_NameEn] =@Address_NameEn )
	AND  ( [Postal_Code] =@Postal_Code )
	AND  ( [Address_Notes] =@Address_Notes )
	AND  ( [Address_Search] =@Address_Search )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Addresses-update]    Script Date: [[20120914064947]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064947]]
-- Description:	Update record in table [dbo].[Addresses]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Addresses-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Addresses-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Addresses-update]
	/*@Address_RowNumber int =Null OUTPUT , 
	@Address_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Address_Code varchar(50) =Null  , 
	@Country_ID uniqueidentifier =Null  , 
	@State_NameAr varchar(50) =Null  , 
	@State_NameEn varchar(50) =Null  , 
	@Town_NameAr varchar(50) =Null  , 
	@Town_NameEn varchar(50) =Null  , 
	@Address_NameAr varchar(50) =Null  , 
	@Address_NameEn varchar(50) =Null  , 
	@Postal_Code varchar(50) =Null  , 
	@Address_Notes varchar(max) =Null  , 
	@Address_Search varchar(max) =Null  , 
	@Address_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [Address_TimeStamp]
    FROM [dbo].[Addresses]
    	WHERE ([Address_ID] = @Address_ID)

    IF  @OldTimeStamp = @Address_TimeStamp
    BEGIN*/
		Update [dbo].[Addresses] SET 
		/*[Address_ID] =@Address_ID, 
		[Dealer_ID] =@Dealer_ID, 
		[Address_Code] =@Address_Code, 
		[Country_ID] =@Country_ID, 
		[State_NameAr] =@State_NameAr, 
		[State_NameEn] =@State_NameEn, 
		[Town_NameAr] =@Town_NameAr, 
		[Town_NameEn] =@Town_NameEn, 
		[Address_NameAr] =@Address_NameAr, 
		[Address_NameEn] =@Address_NameEn, 
		[Postal_Code] =@Postal_Code, 
		[Address_Notes] =@Address_Notes, 
		[Address_Search] =@Address_Search*/
		/*WHERE ([Address_ID] = @Address_ID)*/
	/*END*/

	/*SELECT @Address_RowNumber = [Address_RowNumber], @Address_TimeStamp = [Address_TimeStamp]
    FROM [dbo].[Addresses]
	WHERE ([Address_ID] = @Address_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Addresses-Insert-Update]    Script Date: [[20120914064947]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064947]]
-- Description:	Insert OR Update record into table [dbo].[Addresses]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Addresses-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Addresses-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Addresses-Insert-Update]
	/*@Address_RowNumber int =Null OUTPUT , 
	@Address_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Address_Code varchar(50) =Null  , 
	@Country_ID uniqueidentifier =Null  , 
	@State_NameAr varchar(50) =Null  , 
	@State_NameEn varchar(50) =Null  , 
	@Town_NameAr varchar(50) =Null  , 
	@Town_NameEn varchar(50) =Null  , 
	@Address_NameAr varchar(50) =Null  , 
	@Address_NameEn varchar(50) =Null  , 
	@Postal_Code varchar(50) =Null  , 
	@Address_Notes varchar(max) =Null  , 
	@Address_Search varchar(max) =Null  , 
	@Address_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Addresses] 
					/*WHERE ([Address_ID] = @Address_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Addresses](/*[Address_ID], [Dealer_ID], [Address_Code], [Country_ID], [State_NameAr], [State_NameEn], [Town_NameAr], [Town_NameEn], [Address_NameAr], [Address_NameEn], [Postal_Code], [Address_Notes], [Address_Search]*/)
		VALUES     (/*@Address_ID, @Dealer_ID, @Address_Code, @Country_ID, @State_NameAr, @State_NameEn, @Town_NameAr, @Town_NameEn, @Address_NameAr, @Address_NameEn, @Postal_Code, @Address_Notes, @Address_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [Address_TimeStamp]
		FROM [dbo].[Addresses]
    	WHERE ([Address_ID] = @Address_ID)

		IF  @OldTimeStamp = @Address_TimeStamp
		BEGIN*/
			Update [dbo].[Addresses] SET 
			/*[Address_ID] =@Address_ID, 
			[Dealer_ID] =@Dealer_ID, 
			[Address_Code] =@Address_Code, 
			[Country_ID] =@Country_ID, 
			[State_NameAr] =@State_NameAr, 
			[State_NameEn] =@State_NameEn, 
			[Town_NameAr] =@Town_NameAr, 
			[Town_NameEn] =@Town_NameEn, 
			[Address_NameAr] =@Address_NameAr, 
			[Address_NameEn] =@Address_NameEn, 
			[Postal_Code] =@Postal_Code, 
			[Address_Notes] =@Address_Notes, 
			[Address_Search] =@Address_Search*/
			/*WHERE ([Address_ID] = @Address_ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Address_RowNumber = [Address_RowNumber], @Address_TimeStamp = [Address_TimeStamp]
    FROM [dbo].[Addresses]
	WHERE ([Address_ID] = @Address_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Addresses-Delete]    Script Date: [[20120914064947]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064947]]
-- Description:	delete records from table [dbo].[Addresses] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Addresses-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Addresses-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Addresses-Delete]
	/*@Address_RowNumber int =null  , 
	@Address_ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Address_Code varchar(50) =null  , 
	@Country_ID uniqueidentifier =null  , 
	@State_NameAr varchar(50) =null  , 
	@State_NameEn varchar(50) =null  , 
	@Town_NameAr varchar(50) =null  , 
	@Town_NameEn varchar(50) =null  , 
	@Address_NameAr varchar(50) =null  , 
	@Address_NameEn varchar(50) =null  , 
	@Postal_Code varchar(50) =null  , 
	@Address_Notes varchar(max) =null  , 
	@Address_Search varchar(max) =null  , 
	@Address_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Addresses]
	WHERE /*( [Address_RowNumber] = ISNULL(@Address_RowNumber, [Address_RowNumber]) )
	AND ( [Address_ID] = ISNULL(@Address_ID, [Address_ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Address_Code] like ISNULL(@Address_Code, [Address_Code]) )
	AND ( [Country_ID] = ISNULL(@Country_ID, [Country_ID]) )
	AND ( [State_NameAr] like ISNULL(@State_NameAr, [State_NameAr]) )
	AND ( [State_NameEn] like ISNULL(@State_NameEn, [State_NameEn]) )
	AND ( [Town_NameAr] like ISNULL(@Town_NameAr, [Town_NameAr]) )
	AND ( [Town_NameEn] like ISNULL(@Town_NameEn, [Town_NameEn]) )
	AND ( [Address_NameAr] like ISNULL(@Address_NameAr, [Address_NameAr]) )
	AND ( [Address_NameEn] like ISNULL(@Address_NameEn, [Address_NameEn]) )
	AND ( [Postal_Code] like ISNULL(@Postal_Code, [Postal_Code]) )
	AND ( [Address_Notes] like ISNULL(@Address_Notes, [Address_Notes]) )
	AND ( [Address_Search] like ISNULL(@Address_Search, [Address_Search]) )
	AND ( [Address_TimeStamp] = ISNULL(@Address_TimeStamp, [Address_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Addresses-Select]    Script Date: [[20120914064947]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064947]]
-- Description:	select records from table [dbo].[Addresses] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Addresses-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Addresses-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Addresses-Select]
	/*@Address_RowNumber int =null  , 
	@Address_ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Address_Code varchar(50) =null  , 
	@Country_ID uniqueidentifier =null  , 
	@State_NameAr varchar(50) =null  , 
	@State_NameEn varchar(50) =null  , 
	@Town_NameAr varchar(50) =null  , 
	@Town_NameEn varchar(50) =null  , 
	@Address_NameAr varchar(50) =null  , 
	@Address_NameEn varchar(50) =null  , 
	@Postal_Code varchar(50) =null  , 
	@Address_Notes varchar(max) =null  , 
	@Address_Search varchar(max) =null  , 
	@Address_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Addresses]
	WHERE /*( [Address_RowNumber] = ISNULL(@Address_RowNumber, [Address_RowNumber]) )
	AND ( [Address_ID] = ISNULL(@Address_ID, [Address_ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Address_Code] like ISNULL(@Address_Code, [Address_Code]) )
	AND ( [Country_ID] = ISNULL(@Country_ID, [Country_ID]) )
	AND ( [State_NameAr] like ISNULL(@State_NameAr, [State_NameAr]) )
	AND ( [State_NameEn] like ISNULL(@State_NameEn, [State_NameEn]) )
	AND ( [Town_NameAr] like ISNULL(@Town_NameAr, [Town_NameAr]) )
	AND ( [Town_NameEn] like ISNULL(@Town_NameEn, [Town_NameEn]) )
	AND ( [Address_NameAr] like ISNULL(@Address_NameAr, [Address_NameAr]) )
	AND ( [Address_NameEn] like ISNULL(@Address_NameEn, [Address_NameEn]) )
	AND ( [Postal_Code] like ISNULL(@Postal_Code, [Postal_Code]) )
	AND ( [Address_Notes] like ISNULL(@Address_Notes, [Address_Notes]) )
	AND ( [Address_Search] like ISNULL(@Address_Search, [Address_Search]) )
	AND ( [Address_TimeStamp] = ISNULL(@Address_TimeStamp, [Address_TimeStamp]) )*/
END
GO
-- =============================================
